/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.message_objectsLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class message_objectsClp extends BaseModelImpl<message_objects>
	implements message_objects {
	public message_objectsClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return message_objects.class;
	}

	@Override
	public String getModelClassName() {
		return message_objects.class.getName();
	}

	@Override
	public long getPrimaryKey() {
		return _messageobjectsID;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setMessageobjectsID(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _messageobjectsID;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("messageobjectsID", getMessageobjectsID());
		attributes.put("object_id", getObject_id());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long messageobjectsID = (Long)attributes.get("messageobjectsID");

		if (messageobjectsID != null) {
			setMessageobjectsID(messageobjectsID);
		}

		Long object_id = (Long)attributes.get("object_id");

		if (object_id != null) {
			setObject_id(object_id);
		}
	}

	@Override
	public long getMessageobjectsID() {
		return _messageobjectsID;
	}

	@Override
	public void setMessageobjectsID(long messageobjectsID) {
		_messageobjectsID = messageobjectsID;

		if (_message_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _message_objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setMessageobjectsID",
						long.class);

				method.invoke(_message_objectsRemoteModel, messageobjectsID);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getObject_id() {
		return _object_id;
	}

	@Override
	public void setObject_id(long object_id) {
		_object_id = object_id;

		if (_message_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _message_objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObject_id", long.class);

				method.invoke(_message_objectsRemoteModel, object_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getmessage_objectsRemoteModel() {
		return _message_objectsRemoteModel;
	}

	public void setmessage_objectsRemoteModel(
		BaseModel<?> message_objectsRemoteModel) {
		_message_objectsRemoteModel = message_objectsRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _message_objectsRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_message_objectsRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			message_objectsLocalServiceUtil.addmessage_objects(this);
		}
		else {
			message_objectsLocalServiceUtil.updatemessage_objects(this);
		}
	}

	@Override
	public message_objects toEscapedModel() {
		return (message_objects)ProxyUtil.newProxyInstance(message_objects.class.getClassLoader(),
			new Class[] { message_objects.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		message_objectsClp clone = new message_objectsClp();

		clone.setMessageobjectsID(getMessageobjectsID());
		clone.setObject_id(getObject_id());

		return clone;
	}

	@Override
	public int compareTo(message_objects message_objects) {
		long primaryKey = message_objects.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof message_objectsClp)) {
			return false;
		}

		message_objectsClp message_objects = (message_objectsClp)obj;

		long primaryKey = message_objects.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(5);

		sb.append("{messageobjectsID=");
		sb.append(getMessageobjectsID());
		sb.append(", object_id=");
		sb.append(getObject_id());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(10);

		sb.append("<model><model-name>");
		sb.append(
			"de.hsmannheim.pepa.patientenportal.apanwep.model.message_objects");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>messageobjectsID</column-name><column-value><![CDATA[");
		sb.append(getMessageobjectsID());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>object_id</column-name><column-value><![CDATA[");
		sb.append(getObject_id());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _messageobjectsID;
	private long _object_id;
	private BaseModel<?> _message_objectsRemoteModel;
}